<template>
	<view class="bgview">
		<view class="item" @click="itemClick">
			<view>{{data.userName}}</view>
			<view>性别:{{data.userSexName}}</view>
			<view>年龄:{{getYear(data.userBirthDate)}}岁</view>
		</view>
		<view class="item">
			<view>学历:{{data.userEducationName}}</view>
			<view>报名时间:{{data.createTime}}</view>
			<view><button class="callbtn" @click="playTel(data)">立即联系</button></view>
		</view>
		<view class="lineview"></view>
	</view>
</template>

<script>
	import moment from 'moment';
	export default {
		name: "entryItem",
		props: {
			data: {
				type: Object,
				default () {
					return {};
				},
			},
		},
		data() {
			return {

			};
		},
		methods: {
			playTel(){
				uni.makePhoneCall({
					phoneNumber: this.data.userPhone,
					success: function() {
						console.log('拨打电话成功！');
					},
					fail: function() {
						console.log('拨打电话失败！');
					}
				});
			},
			getSex(index) {
				// switch (index) {
				// 	case:
				// 		0
				// 		return "男"
				// 	case:
				// 		1
						return "女"
				// 	default
				// }
			},
			getYear(time) {
				let startDate = new Date(time); // 开始日期
				let endDate = new Date(); // 结束日期（当前时间）
				let yearsDiff = moment(endDate).diff(startDate, 'years');
				console.log(`两个日期相差 ${yearsDiff} 年`);
				return yearsDiff;
				//javascript
				// 假设接口返回的年龄为生日的日期字符串，如 '1990-01-01'
				// const birthday = time;

				// const now = new Date(); // 获取当前日期
				// const birthDate = new Date(birthday); // 将生日字符串转换为日期对象
				// const ageDiff = now.getFullYear() - birthDate.getFullYear(); // 计算年龄差值

				// // 如果生日还未过，则年龄减1
				// if (now.getMonth() < birthDate.getMonth() || (now.getMonth() === birthDate.getMonth() && now.getDate() <
				// 		birthDate.getDate())) {
				// 	ageDiff--;
				// }
				// console.log(ageDiff); // 输出：31
				// // 判断年龄是否是周岁
				// const isFullAge = ageDiff >= 1;
				// console.log(isFullAge); // 输出：true
				// return ageDiff
			},
			itemClick() {
				this.$emit("itemClick", {
					data: this.data
				});
			},
		}
	}
</script>

<style lang="scss">
	.callbtn {
		margin-top: -10rpx;
		height: 60rpx;
		line-height: 60rpx;
		width: 180rpx;
		text-align: center;
		color: #fff;
		border-radius: 8rpx;
		background: #0575ff;
		font-size: 28rpx;
	}

	.lineview {
		background-color: #F6F6F6;
		width: 100%;
		height: 5px;
	}

	.bgview {
		background-color: #F6F6F6;
		padding-top: 10px;
		background-color: white;
		display: flex;
		flex-direction: column;
		padding: 15px;

		.item1 {
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			text-align: center;
		}

		.item {
			margin-top: 15px;
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			text-align: center;
			padding-bottom: 15px;
		}
	}
</style>